﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using CsToYjk;
using RevitData;
using DataFuncApplication;

namespace ConsoleApp4
{
    class kjjgtest
    {
        static void Main(string[] args)
        {
            //标准层
            Mdl_StdFlr bzc = DataFunc.StdFlr_Generate(3600);
            //空间层
            Mdl_StdFlr kjc = DataFunc.SpcFlr_Generate();
            //定义柱
            Mdl_ColSect defcol1 = DataFunc.ColSect_Def(6, 1, "600,600");
            Mdl_ColSect defcol2 = DataFunc.ColSect_Def(6, 1, "800,1100");
            //定义梁
            Mdl_BeamSect defbeam1 = DataFunc.BeamSect_Def(6, 1, "350,800");
            Mdl_BeamSect defbeam2 = DataFunc.BeamSect_Def(6, 1, "600,900");
            //定义斜杆
            Mdl_BraceSect defbrace1 = DataFunc.BraceSect_Def(5, 8, "180,166");
            Mdl_BraceSect defbrace2 = DataFunc.BraceSect_Def(5, 8, "102,92");
            Mdl_BraceSect defbrace3 = DataFunc.BraceSect_Def(5, 8, "219,199");
            //定义荷载
            Mdl_LoadSect beamload1 = DataFunc.def_load("beam", "1.00,8.00,0.00,0.00,0.00,0.00,0.00");
            Mdl_LoadSect beamload2 = DataFunc.def_load("beam", "1.00,8.50,0.00,0.00,0.00,0.00,0.00");
            //布置框架结构
            var originpos = new List<List<int>>();
            originpos.Add(new List<int> { 0, 0 });
            originpos.Add(new List<int> { 0, 27900});
            originpos.Add(new List<int> { 64800, 0});
            originpos.Add(new List<int> { 64800, 27900});

            var xspans = new List<int>();
            var yspans = new List<int>();
            foreach (var node in originpos)
            {
                xspans = new List<int> { node[0], 3600, 3600, 3600, 3600};
                yspans = new List<int> { node[1], 8400};
                var nodelist = DataFunc.node_generate(xspans, yspans, bzc);
                DataFunc.column_arrange(nodelist, defcol1);
                var gridlist_beam1 = DataFunc.grid_generate(nodelist, 1, 1);
                var beam_list = DataFunc.beam_arrange(gridlist_beam1, defbeam1);
                DataFunc.load_arrange(beam_list, beamload1);
            }
            originpos.Clear();
            originpos.Add(new List<int> { 0, 8400 });
            originpos.Add(new List<int> { 64800, 8400 });
            foreach (var node in originpos)
            {
                xspans = new List<int> { node[0], 3600, 3600, 3600, 3600 };
                yspans = new List<int> { node[1], 6500, 6500, 6500 };
                var nodelist = DataFunc.node_generate(xspans, yspans, bzc);
                DataFunc.column_arrange(nodelist, defcol1);
                var gridlist_beam2 = DataFunc.grid_generate(nodelist, 1, 1);
                var beam_list = DataFunc.beam_arrange(gridlist_beam2, defbeam1);
                DataFunc.load_arrange(beam_list, beamload1);
                xspans = new List<int> { node[0], 14400 };
                yspans = new List<int> { 11650, 6500, 6500 };
                nodelist = DataFunc.node_generate(xspans, yspans, bzc);
                var gridlist_beam3 = DataFunc.grid_generate(nodelist, 1, 0);
                beam_list = DataFunc.beam_arrange(gridlist_beam3, defbeam1);
                DataFunc.load_arrange(beam_list, beamload2);
            }
            xspans = new List<int> { 14400, 7200, 7200, 7200, 7200, 7200, 7200, 7200 };
            yspans = new List<int> { 0, 36300 };
            {
                var nodelist = DataFunc.node_generate(xspans, yspans, bzc);
                DataFunc.column_arrange(nodelist, defcol2);
                var gridlist_beam3 = DataFunc.grid_generate(nodelist, 1, 0);
                var beam_list = DataFunc.beam_arrange(gridlist_beam3, defbeam2);
                DataFunc.load_arrange(beam_list, beamload1);
                DataFunc.slab_arrange(39600, 18150, 0, bzc, true);
            }
            originpos.Clear();
            originpos.Add(new List<int> { 20400, 0 });
            //布置主桁架
            for (int i = 0; i < 6; ++i)
            {
                xspans = new List<int> { originpos[0][0] + i * 7200, 2400 };
                yspans = new List<int> { };
                for (int j = 0; j < 15; ++j)
                {
                    yspans.Add(2420);
                }
                yspans.Insert(0, originpos[0][1]);
                var node_down_y = new List<int>();
                for (int j = 0; j < 14; ++j)
                {
                    node_down_y.Add(2420);
                }
                node_down_y.Insert(0, originpos[0][1] + 2420 / 2);

                var node_down = DataFunc.node_generate(new List<int>() { xspans[0] + xspans[1] / 2 }, node_down_y, kjc, 10707);
                var nodelist = DataFunc.node_generate(xspans, yspans, kjc, 13100);
                var nodelist_brace1 = new List<List<Mdl_Joint>>();
                var nodelist_brace2 = new List<List<Mdl_Joint>>();
                var nodelist_brace3 = new List<List<Mdl_Joint>>();
                for (int j = 0; j < 15; ++j)
                {
                    nodelist_brace1.Add(new List<Mdl_Joint>() { nodelist[0][j], nodelist[0][j + 1] });
                }
                for(int j = 0; j < 15; ++j)
                {
                    nodelist_brace1.Add(new List<Mdl_Joint>() { nodelist[1][j], nodelist[1][j + 1] });
                }
                for (int j = 0; j < 15; ++j)
                {
                    nodelist_brace2.Add(new List<Mdl_Joint>() { node_down[0][j], nodelist[0][j] });
                    nodelist_brace2.Add(new List<Mdl_Joint>() { node_down[0][j], nodelist[1][j] });
                    nodelist_brace2.Add(new List<Mdl_Joint>() { node_down[0][j], nodelist[0][j+1] });
                    nodelist_brace2.Add(new List<Mdl_Joint>() { node_down[0][j], nodelist[1][j+1] });
                    nodelist_brace2.Add(new List<Mdl_Joint>() { nodelist[0][j+1], nodelist[1][j + 1] });
                    if ((j+1)%2==1)
                    {
                        nodelist_brace2.Add(new List<Mdl_Joint>() { nodelist[0][j + 1], nodelist[1][j]});
                    }
                    else
                    {
                        nodelist_brace2.Add(new List<Mdl_Joint>() { nodelist[1][j + 1], nodelist[0][j]});
                    }
                }
                DataFunc.brace_arrange(nodelist_brace2, defbrace2);
                for(int j=0;j< node_down[0].Count-1;++j)
                {
                    nodelist_brace3.Add(new List<Mdl_Joint>() { node_down[0][j], node_down[0][j + 1] });
                }
                DataFunc.brace_arrange(nodelist_brace1, defbrace1);
                DataFunc.brace_arrange(nodelist_brace3, defbrace3);
            }
            //布置次桁架
            var SecTruss_infos_left = new List<List<int>>();
            var SecTruss_infos_right = new List<List<int>>();
            var SecTruss_infos_mid = new List<List<int>>();
            SecTruss_infos_left.Add(new List<int> { 14400, 7260, 2000, 3 });
            SecTruss_infos_left.Add(new List<int> { 14400, 14520, 2000, 3 });
            SecTruss_infos_left.Add(new List<int> { 14400, 19360, 2000, 3 });
            SecTruss_infos_left.Add(new List<int> { 14400, 26620, 2000, 3 });
            SecTruss_infos_right.Add(new List<int> { 58800, 7260, 2000, 3 });
            SecTruss_infos_right.Add(new List<int> { 58800, 14520, 2000, 3 });
            SecTruss_infos_right.Add(new List<int> { 58800, 19360, 2000, 3 });
            SecTruss_infos_right.Add(new List<int> { 58800, 26620, 2000, 3 });
            for(int r=0;r<2;++r)
            {
                for(int c=0;c<5;++c)
                {
                    var tmp = new List<int>() { 22800 + c * 7200, 14520 + r * 4840, 1600, 3 };
                    SecTruss_infos_mid.Add(tmp);
                }
            }
            var SecTruss_infos = new List<List<int>>();
            SecTruss_infos.AddRange(SecTruss_infos_left);
            SecTruss_infos.AddRange(SecTruss_infos_right);
            SecTruss_infos.AddRange(SecTruss_infos_mid);
            foreach(var SecTruss_info in SecTruss_infos)
            {
                var nodelist_brace1 = new List<List<Mdl_Joint>>();
                var nodelist_brace2 = new List<List<Mdl_Joint>>();
                var nodelist_brace3 = new List<List<Mdl_Joint>>();
                yspans = new List<int>() { SecTruss_info[1], 2420};
                xspans.Clear();
                for (int j=0;j< SecTruss_info[3];++j)
                {
                    xspans.Add(SecTruss_info[2]);
                }
                xspans.Insert(0, SecTruss_info[0]);
                var node_down_x= new List<int>() { SecTruss_info[2] , SecTruss_info[2] };
                node_down_x.Insert(0, SecTruss_info[0] + SecTruss_info[2] / 2);
                var node_down = DataFunc.node_generate(node_down_x, new List<int>() { yspans[0] + yspans[1] / 2 }, kjc, 10707);
                var nodelist = DataFunc.node_generate(xspans, yspans, kjc, 13100);
                for (int j = 0; j < SecTruss_info[3]; ++j)
                {
                    nodelist_brace1.Add(new List<Mdl_Joint>() { nodelist[j][0], nodelist[j+1][0] });
                }
                for (int j = 0; j < SecTruss_info[3]; ++j)
                {
                    nodelist_brace1.Add(new List<Mdl_Joint>() { nodelist[j][1], nodelist[j+1][1] });
                }
                for (int j = 0; j < SecTruss_info[3]; ++j)
                {
                    nodelist_brace2.Add(new List<Mdl_Joint>() { node_down[j][0], nodelist[j][0] });
                    nodelist_brace2.Add(new List<Mdl_Joint>() { node_down[j][0], nodelist[j][1] });
                    nodelist_brace2.Add(new List<Mdl_Joint>() { node_down[j][0], nodelist[j+1][0] });
                    nodelist_brace2.Add(new List<Mdl_Joint>() { node_down[j][0], nodelist[j+1][1] });
                    nodelist_brace2.Add(new List<Mdl_Joint>() { nodelist[j+1][0], nodelist[j+1][1] });
                    if ((j + 1) % 2 == 1)
                    {
                        nodelist_brace2.Add(new List<Mdl_Joint>() { nodelist[j+1][0], nodelist[j][1] });
                    }
                    else
                    {
                        nodelist_brace2.Add(new List<Mdl_Joint>() { nodelist[j+1][1], nodelist[j][0] });
                    }
                }
                DataFunc.brace_arrange(nodelist_brace2, defbrace2);
                for (int j = 0; j < node_down[0].Count - 1; ++j)
                {
                    nodelist_brace3.Add(new List<Mdl_Joint>() { node_down[0][j], node_down[0][j + 1] });
                }
                DataFunc.brace_arrange(nodelist_brace2, defbrace2);
                DataFunc.brace_arrange(nodelist_brace1, defbrace2);
            }

            //布置此桁架的下弦杆
            xspans = new List<int> { 15400, 2000, 2000, 2200 };
            yspans= new List<int> { 8470, 7260, 4840, 7260 };
            DataFunc.simple_truss(xspans, yspans, 10707, kjc, defbrace2, 1, 0);
            xspans = new List<int> { 57600, 2200, 2000, 2000 };
            yspans = new List<int> { 8470, 7260, 4840, 7260 };
            DataFunc.simple_truss(xspans, yspans, 10707, kjc, defbrace2, 1, 0);
            originpos.Clear();
            originpos.Add(new List<int> { 21600, 15730 });
            originpos.Add(new List<int> { 28800, 15730 });
            originpos.Add(new List<int> { 36000, 15730 });
            originpos.Add(new List<int> { 43200, 15730 });
            originpos.Add(new List<int> { 50400, 15730 });
            foreach(var p in originpos)
            {
                xspans= new List<int> { p[0], 2000, 1600, 1600, 2000 };
                yspans = new List<int> { p[1], 4840 };
                DataFunc.simple_truss(xspans, yspans, 10707, kjc, defbrace2, 1, 0);
            }
            //布置桁架上弦杆与周边框架搭接的部分
            xspans = new List<int> { 14400, 6000, 2400, 4800, 2400, 4800, 2400, 4800, 2400, 4800, 2400, 4800, 2400, 6000 };
            yspans = new List<int> { 0, 36300 };
            DataFunc.simple_truss(xspans, yspans, 13100, kjc, defbrace2, 1, 0,-500);
            xspans = new List<int> { 14400, 50400 };
            yspans = new List<int> { 0, 7260, 2420, 4840, 2420, 2420, 2420, 4840, 2420, 7260 };
            DataFunc.simple_truss(xspans, yspans, 13100, kjc, defbrace2, 0, 1, -500);
            //标准层复制
            DataFunc.bzc_copy(0, bzc, 3, 4200);
            DataFunc.bzc_copy(0, kjc, 1, 0);
            //提交建模数据
            DataFunc.DbModel_Assign();
            Hi_AddProjectToYjk my = new Hi_AddProjectToYjk(DataFunc.model);
            bool isok = my.CreateYDB("C:\\Users\\10497\\Desktop\\ConsoleApp\\ConsoleApp4");
            if (isok) Console.WriteLine("运行完成！");
            Console.ReadLine();
        }
    }
}
